<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="/WEB-INF/html.tld" prefix="html" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<form:form id="financialProduct" modelAttribute ="financial" method="POST" action="${addFinancial}" name="financialProduct">

<html:table attributes="class='inputTable' style='width:100%'">
  <html:tr>
    <html:td><label><spring:message code="label.finance.product.name" /></label></html:td>
    <html:td><label><spring:message code="label.finance.product.code" /></label></html:td>
    <html:td><label><spring:message code="label.finance.product.type" /></label></html:td>
    <html:td><label><spring:message code="label.promotional.code" /></label></html:td>
  </html:tr>
  <html:tr>
    <html:td append="div"><form:input path="financial.name" name="financial.name"></form:input></html:td>
    <html:td append="div"><form:input path="financial.financialProductCode" name="financial.financialProductCode" class='required'></form:input></html:td>
    <html:td append="div"><form:input path='financial.productType' name='financial.productType'></form:input></html:td>
    <html:td append="div"><form:input path='financial.promotionalCode' name='financial.promotionalCode'></form:input></html:td>
  </html:tr>
  <html:tr>
    <html:td><label><spring:message code="label.min.amount" /> </label></html:td>
    <html:td><label><spring:message code="label.max.amount" /></label></html:td>
    <html:td><label><spring:message code="label.effective.date" /> </label></html:td>
    <html:td><label><spring:message code="label.expiry.date" /></label></html:td>
  </html:tr>
   <html:tr>
    <html:td append="div"><form:input path="financial.lowerAmount" class="amount required" name="financial.lowerAmount"></form:input></html:td>
    <html:td append="div"><form:input path="financial.upperAmount" class="amount required" name="financial.upperAmount" ></form:input></html:td>
    <html:td append="div"><form:input path='financial.startDate' class="date required" name='financial.startDate'></form:input></html:td>
    <html:td append="div"><form:input path='financial.expiryDate' class="date required" name='financial.expiryDate'></form:input></html:td>
  </html:tr>

    <html:tr>
    <td colspan='4'>
    	<table>
    	<tr>
    	<td><form:checkbox path="financial.isDefault" value="Y"/><label for="">Default</label></td>
    	<td><form:checkbox path="financial.isRateProtected" value="Y"/><label for="">Rate Protected</label></td>
    	</tr>
    	<tr>
    	<td><form:checkbox path="financial.isAmortization" value="Y"/><label for="">Allow Amortization</label></td>
    	<td><label for="financial.isSameAsTerm"><form:checkbox path='financial.isSameAsTerm' value="Y"/>Same As Term</label></td>
    	</tr>
    	<tr>
    	<td><form:input path="financial.termsIn" class="number" size="3"/><label for="">Terms In</label></td>
    	<td><form:input path='financial.termsGapBy' class="number" size="3"/><label for="">Terms Gap By(In Months)</label></td>
    	</tr>
    	<tr>
    	<td><form:input path="financial.minTerm" class="number" size="3"/><label for="">Min Term</label></td>
    	<td><form:input path='financial.maxTerm' class="number" size="3"/><label for="">Max Term</label></td>
    	</tr>
    	<tr>
    	<td><form:input path="financial.dealerFees" class="number" size="3"/><label for="">Dealer Fees</label></td>
    	<td><form:input path='financial.serviceTax' class="number" size="3"/><label for="">Service Tax</label></td>
    	</tr>
    	</table>
    	</td>
  
   
   
  </html:tr>
  
  
   
  
</html:table>
 <form:input path="financial.financialProductId"  name="financial.financialProductId"/>
</form:form>
  <div id="contain" style="display:none;width:auto;overflow:auto;position:absolute;"></div>
	        
	  
<script type="text/javascript">

$(function () {
	
	  //$( "input[type='checkbox']" ).button();
	  
	  
});


function addProduct()
{
	//$('.amount').inputmask('remove');
	//TODO:put below lines inside the doAjaxMethod. and explain what does it means.
	jQuery.ajaxSettings.traditional = true;

	var formData = $("#financialProduct").serializeObject();
	//formData.rateCards=assignedRate;
<c:url var="addFinancial" value="/admin/financial/add" />
	var params={url:"${addFinancial}",success:onSuccess,data:formData,type:"POST",dataType:"json"};
	doAjax(params);
}



function onSuccess(result)
{
	console.log(result);
	console.log(result.objectName);
 	$("input[name='"+result.objectName+"']").val(result.objectId);
 	
 	//TODO:ajax error rendering put it on common place
 	$( result.fieldError).each(function() {
		console.log(this.field);
		$('input[name="'+this.field+'"]').css( "border",'1px solid red' );
	});
}



</script>

 
    